package stringbuilder;

import java.util.Arrays;

public class StringBuilderTest {
    public static void main(String[] args) {
        //漂亮的打印数组
        int[] arr = {1,2,3,4,5};
        //最简单也是最推荐的
        System.out.println("Arrays.toString(arr) = " + Arrays.toString(arr));
       
        //一点点打印
        System.out.println("[");
        for (int i = 0; i < arr.length; i++) {
            if (i==arr.length-1){
                System.out.println(arr[i] + "]");
                
            }else {
                System.out.println(arr[i]+",");
            }
        }
        //用字符串拼接好 然后一次性打印
        String sum = "[";
        for (int i = 0; i < arr.length; i++) {
            if (i==arr.length-1){
                sum += (arr[i] +"]");
                
            }else {
                sum +=(arr[i] + ",");
            }
        }
        System.out.println("sum = " + sum);
        
        
        //用sb对象实现
        StringBuilder sbSum = new StringBuilder("[");
        for (int i = 0; i < arr.length; i++) {
            if (i==arr.length-1){
                sbSum.append(arr[i]).append("]");
            }else {
                sbSum.append(arr[i]).append(",");

            }
            
        }
        System.out.println("sbSum = " + sbSum);
    }
}
